package com.lm.integration.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.messaging.MessageChannel;

@Configuration
public class IntegrationConfig {

    // 定义一个直连通道
    @Bean
    public MessageChannel inputChannel() {
        return new DirectChannel();
    }

    @Bean
    public MessageChannel outputChannel() {
        return new DirectChannel();
    }

    // 定义消息流
    @Bean
    public IntegrationFlow demoFlow() {
        return IntegrationFlows.from(inputChannel())
                .transform(String.class, msg -> "处理后消息: " + msg)
                .handle(msg -> System.out.println("Received: " + msg.getPayload()))
                .get();
    }
}